﻿//多个字符从两端移动，向中间汇聚
/*#include<stdio.h>
#include<string.h>
#include<windows.h>
int main()
{
	char arr1[] =  "I LOVE YOU";//字符用双引号
	char arr2[] =  "**********";
	int left = 0;
	int right = strlen(arr1) - 1;//the difference of strlen and sizeof 
	printf("%s\n", arr2);
	while (left<=right)
	{
		Sleep(1000);//make program stop
		arr2[left] = arr1[left];
		arr2[right] = arr1[right];
		left++;
		right--;
		printf("%s\n", arr2);
	}
	return 0;
}*/
//⼆分查找
#include<stdio.h>
int main()
{
	int arr[] = { 1,2,3,4,5,6,7,8,9,10 };
	int key = 7;
	int right = sizeof(arr) / sizeof(arr[0]) - 1;
	int left = 0;
	int mid = 0;
	int find = 0;
	while (right >= left)
	{
		mid = (right + left) / 2;
		if(arr[mid]>arr[key])
		{
			right = mid - 1;
		}
		else if (arr[mid] < arr[key])
		{
			left = mid + 1;
		}
		else
		{
			find = 1;
			break;
		}
	}
	if (find = 1)
	{
		printf("找到了,下标是%d\n",mid);
	}
	else
	{
		printf("找不到\n");
	}
	return 0;
}